//index.js
const app = getApp()

Page({
  data: {
    img: [{
      img: 'http://sd.offcn.com/zg/wximg/2022/gk/gkbk/banner1.png',
      bind: 'icon1'
    }, {
      img: 'http://sd.offcn.com/zg/wximg/2022/gk/gkbk/banner2.png',
      bind: 'banner2'
    }, {
      img: 'http://sd.offcn.com/zg/wximg/2022/gk/gkbk/banner3.png',
      bind: 'banner3'
    }],
    navbarArr: [{
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon1.png',
        viewNavto: 'icon1',
        name: '面试峰会'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon2.png',
        viewNavto: 'icon2',
        name: '进面名单'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon3.png',
        viewNavto: 'icon3',
        name: '国考资料'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon4.png',
        viewNavto: 'icon4',
        name: '面试考情'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon5.png',
        viewNavto: 'icon5',
        name: '进面分数'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/2021/gk/index/icon6.png',
        viewNavto: 'icon6',
        name: '在线咨询'
      },
    ],
    theSwiper: [{
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/new.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_2.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_3.jpg',
        tomini: 'togkbs'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_4.jpg',
        tomini: 'to19'
      }
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1500,
    current: 0,
    area: '默认',
    geneal: '默认'
  },
  banner1: function () {
    var that = this;
    wx.navigateTo({
      url: '../out/msfh/msfh'
    })
  },
  banner2: function () {
    var that = this;
    wx.navigateTo({
      url: '../mianshi/mianshi?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  banner3: function () {
    var that = this;
    wx.navigateTo({
      url: '../query/query?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  icon1: function () {
    var that = this;
    // wx.navigateToMiniProgram({
    //   appId: 'wx3bfce5135e23ad3f', //国考职位查询小程序appid
    //   path: 'pages/search/search/search?area=' + that.data.area + '&agent=' + that.data.geneal + '&page=' + that.data.page , //国考职位查询首页index
    //   envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
    //   success(res) {
    //     console.log('打开成功！')
    //   }
    // })
    wx.navigateTo({
      url: '../out/msfh/msfh'
    })
  },
  icon2: function () {
    var that = this;
    wx.navigateTo({
      url: '../query/query?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  icon3: function () {
    wx.navigateTo({
      url: '../fbook/fbook?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  icon4: function () {
    wx.navigateTo({
      url: '../mianshi/mianshi?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  icon5: function () {
    wx.navigateTo({
      url: '../fsx/fsx?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  icon6: function () {
    wx.navigateTo({
      url: '../zixun/zixun'
    })
  },
  link1: function () {
    wx.navigateTo({
      url: '../link/link1/link1'
    })
  },
  link2: function () {
    wx.navigateTo({
      url: '../link/link2/link2'
    })
  },
  link3: function () {
    wx.navigateTo({
      url: '../link/link3/link3'
    })
  },
  link4: function () {
    wx.navigateTo({
      url: '../link/link4/link4'
    })
  },


  toxiaoneng: function () {
    wx.navigateTo({
      url: '../xiaoneng/xiaoneng'
    })
  },
  toshijuan: function () {
    wx.navigateToMiniProgram({
      appId: 'wx3bfce5135e23ad3f', //国考职位查询小程序appid
      path: 'pages/search/search/search?area=' + that.data.area + '&agent=' + that.data.agent + '&page=' + that.data.page , //国考职位查询首页index
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page
    })
    wx.setStorageSync('area', options.area)
    wx.setStorageSync('agent', options.agent)

    var d = new Date()
    that.setData({
      sheng: 29 - d.getDate()
    })
  },
  swiperChange: function (e) {
    var that = this;
    if (e.detail.source == 'touch') {
      that.setData({
        current: e.detail.current,
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      that.setData({
        mobile: res.result,
      })
      wx.setStorage({
        key: "phone",
        data: res.result
      })
      try {
        var value = wx.getStorageSync('phone')
        if (value) {
          this.setData({
            "navbarArr[0].opentype": 'false',
            "navbarArr[2].opentype": 'false',
            "navbarArr[3].opentype": 'false',
            "navbarArr[7].opentype": 'false',
          });
        }
      } catch (e) {
        // Do something when catch error
      }
      console.log(res.result)
      console.log('cloud phone get success!')
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=21474&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: that.data.area,
          geneal: that.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log('zg99 phone get success !')

        }
      })

      wx.redirectTo({
        url: '../index/index'
      })

    }).catch(err => {
      console.error(err);
    });



  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '2021国家公务员智能职位检索系统 '
    }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var that = this;
    var id = wx.getStorageSync('id')
    return {
      title: '2021国家公务员智能职位检索系统',
      path: 'pages/index/index'
    }
  }


})